﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;

using Happy.CodeRule;
using Happy.CodeRule.Generators;

namespace Happy.CodeRule.Test
{
    [TestClass]
    public class CodeRuleInterceptorTest
    {
        [TestMethod]
        public void Intercept_Test()
        {
            var seedKey = "销售订单";
            var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Seeds", seedKey + ".txt");
            if (File.Exists(file))
            {
                File.Delete(file);
            }

            var interceptor = new CodeRuleInterceptor();

            interceptor
                .RegisterInterceptor(new DateTimeCodeGeneratorInterceptor())
                .RegisterInterceptor(new LiteralCodeGeneratorInterceptor())
                .RegisterInterceptor(new SeedCodeGeneratorInterceptor(new FileSeedStore()));

            var generator = interceptor.Intercept("前缀---<日期:yyyyMMdd>---中缀---<种子:销售订单>---后缀");

            Assert.IsNotNull(generator);


            Assert.AreEqual("前缀---" + DateTime.Now.ToString("yyyyMMdd") + "---中缀---00001---后缀", generator.Generate(new GenerateContext()));
            Assert.AreEqual("前缀---" + DateTime.Now.ToString("yyyyMMdd") + "---中缀---00002---后缀", generator.Generate(new GenerateContext()));
            Assert.AreEqual("前缀---" + DateTime.Now.ToString("yyyyMMdd") + "---中缀---00003---后缀", generator.Generate(new GenerateContext()));
        }
    }
}
